package utils;

import java.util.ArrayList;
import java.util.List;
import com.zcfeng.ischool.R;

import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class ToolBarUtils {
	private static List<Button> list=new ArrayList<Button>();
	public void createToolBar(LinearLayout tbar, String[] toolbarTittle){
		tbar.removeAllViews();
		list.clear();
		for(int i=0;i<toolbarTittle.length;i++)
		{
			Button tv=(Button) View.inflate(tbar.getContext(), R.layout.under_button, null);
			tv.setText(toolbarTittle[i]);
			final int s=i;
			int width=0;
			int height = LayoutParams.MATCH_PARENT;
			LayoutParams param = new LayoutParams(width, height);
			param.weight=1;
			tbar.addView(tv,param);
			list.add(tv);
			tv.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if(ontbclick!=null){
						ontbclick.onTBClick(s);
						changecolor(s);
					}
				}
			});
		}
	}
	public void changecolor(int position){
		for(Button tv:list){
			tv.setBackgroundColor(Color.parseColor("#4A8DD3"));
		}
		list.get(position).setBackgroundColor(Color.parseColor("#f0f0f0"));
	}
	/**
	 * 回调步骤
	 * 1.定义接口
	 * 2.定义接口变量
	 * 3.接口变量接口方法
	 * 4。暴露公共方法
	 */
	public interface onTBclick{
		void onTBClick(int position);
	}
	onTBclick ontbclick;
	public void setOntbclick(onTBclick ontbclick) {
		this.ontbclick = ontbclick;
	}

}
